{extend name="layouts/app"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">编辑幻灯片</div>
    <div class="layui-card-body">
        <form class="layui-form" method="post" action="{:url('update')}">
            <div class="layui-form-item">
                <label class="layui-form-label">所属分类</label>
                <div class="layui-input-inline w300">
                    <cascader id="category"></cascader>
                    <input type="hidden" name="category_id" value="{$slide->category_id}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">幻灯片</label>
                <div class="layui-input-inline w300">
                    <a id="seleBtn" class="layui-btn layui-btn-primary" href="javascript:;" data-url="{:url('uploads/image')}"  onclick="popUpload(this)">添加图片</a>
                    <input type="hidden" name="image" value="{$slide->image}"/>
                    <img src="{$slide->previewImage}" style="width:100px;height:100px">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-inline w300">
                    <input type="text" name="title" value="{$slide->title}" autocomplete="off" placeholder="请填写标题" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">简介</label>
                <div class="layui-input-inline w300">
                    <textarea name="description" placeholder="请输入分类描述" class="layui-textarea">{$slide->description}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">跳转链接</label>
                <div class="layui-input-inline w300">
                    <input type="text" name="url" value="{$slide->url}" autocomplete="off" placeholder="请填写链接地址" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-inline w300">
                    <input type="text" name="sort" value="{$slide->sort}" lay-verify="required|number" autocomplete="off" placeholder="请填写数字" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" title="正常" {eq name="$slide->status" value="1" }checked{/eq} >
                    <input type="radio" name="status" value="0" title="隐藏" {eq name="$slide->status" value="0" }checked{/eq} >
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="hidden" name="id" value="{$slide->id}">
                    <button class="layui-btn" lay-submit="" lay-filter="formSubmit">立即提交</button>
                    <button class="layui-btn layui-btn-normal" type="button" onclick="javascript:history.back(-1);">返回</button>
                </div>
            </div>
        </form>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    layui.extend({
        ajaxCascader: 'ajaxCascader/ajaxCascader'
    }).use([ 'form', 'layer','ajaxCascader','layedit'], function () {
        var $ = layui.$,
            ajaxCascader=layui.ajaxCascader,
            layedit = layui.layedit,
            form=layui.form;

        //选择菜单
        ajaxCascader.load({
            elem: '#category'
            ,search: {
                show: true,
                minLabel: 10,
                placeholder: '请输入搜索词'
            }
            ,clear: true
            ,value: 0
            ,chooseData:<?php echo $chooseData; ?>
            ,getChildren: function(value,callback){
                var data = [];
                $.ajax({
                    url:"{:url('apiGetCategory')}",
                    type:'get',
                    data:{parent_id:value},
                    success:function(res){
                        data = res.data;
                        for(var i in data){
                            data[i].value = data[i].id;
                            data[i].label = data[i].title;
                            delete data[i].id;
                            delete data[i].title;
                            data[i].hasChild = data[i].is_directory;
                        }
                        callback(data);
                    }
                });
            }
        });

        ajaxCascader.on('click', '#category', function(data){
            $("input[name='category_id']").val(data.value);
        });
       //富文本编辑器
       var edit_index= layedit.build('confield', {
           height:200,
           uploadImage:{
               url: '/admin/uploads/image' //接口url
               ,type: 'post' //默认post
           }
       });
        form.verify({
            content: function (value) {
                return layedit.sync(edit_index);
            }
        })
    });
</script>
{/block}